package v1

import (
	"fmt"
	"gin-vue-admin/global"
	"gin-vue-admin/model"
	"gin-vue-admin/model/request"
	"gin-vue-admin/model/response"
	"gin-vue-admin/service"

	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
)

// @Tags CustomProcessBase
// @Summary 创建CustomProcessBase
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.CustomProcessBaseBase true "创建CustomProcessBase"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /customProcessBase/createCustomProcessBase [post]
func CreateCustomProcessBase(c *gin.Context) {
	fmt.Println("CreateCustomProcessBase----------")
	fmt.Println(c)
	var customProcessBase model.CustomProcessBase
	fmt.Println(customProcessBase)
	_ = c.ShouldBindJSON(&customProcessBase)
	fmt.Println(customProcessBase)
	if err := service.CreateCustomProcessBase(customProcessBase); err != nil {
		global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// @Tags CustomProcessBase
// @Summary 删除CustomProcessBase
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.CustomProcessBase true "删除CustomProcessBase"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /customProcessBase/deleteCustomProcessBase [delete]
func DeleteCustomProcessBase(c *gin.Context) {
	var customProcessBase model.CustomProcessBase
	_ = c.ShouldBindJSON(&customProcessBase)
	if err := service.DeleteCustomProcessBase(customProcessBase); err != nil {
		global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// @Tags CustomProcessBase
// @Summary 批量删除CustomProcessBase
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除CustomProcessBase"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /customProcessBase/deleteCustomProcessBaseByIds [delete]
func DeleteCustomProcessBaseByIds(c *gin.Context) {
	var IDS request.IdsReq
	_ = c.ShouldBindJSON(&IDS)
	if err := service.DeleteCustomProcessBaseByIds(IDS); err != nil {
		global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// @Tags CustomProcessBase
// @Summary 更新CustomProcessBase
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CustomProcessBaseUpdate true "更新CustomProcessBase"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /customProcessBase/updateCustomProcessBase [put]
func UpdateCustomProcessBase(c *gin.Context) {
	fmt.Println("UpdateCustomProcessBase----------")
	var customProcessBase model.CustomProcessBase
	fmt.Println(customProcessBase)
	_ = c.ShouldBindJSON(&customProcessBase)
	fmt.Println(customProcessBase)

	err, recustomProcessBaseOriginal := service.GetCustomProcessBase(customProcessBase.ID)
	if err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	}
	customProcessBase.CreatedAt = recustomProcessBaseOriginal.CreatedAt

	if err := service.UpdateCustomProcessBase(&customProcessBase); err != nil {
		global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// @Tags CustomProcessBase
// @Summary 用id查询CustomProcessBase
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.GetByIdUnit true "用id查询CustomProcessBase"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /customProcessBase/findCustomProcessBase [get]
func FindCustomProcessBase(c *gin.Context) {
	var customProcessBase request.GetByIdUnit
	_ = c.ShouldBindQuery(&customProcessBase)
	if err, recustomProcessBase := service.GetCustomProcessBase(customProcessBase.Id); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"recustomProcessBase": recustomProcessBase}, c)
	}
}

// @Tags CustomProcessBase
// @Summary 分页获取CustomProcessBase列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.CustomProcessBaseSearch true "分页获取CustomProcessBase列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /customProcessBase/getCustomProcessBaseList [get]
func GetCustomProcessBaseList(c *gin.Context) {
	var pageInfo request.CustomProcessBaseSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := service.GetCustomProcessBaseInfoList(pageInfo); err != nil {
		global.GVA_LOG.Error("获取失败", zap.Any("err", err))
		response.FailWithMessage("获取失败", c)
	} else {
		response.OkWithDetailed(response.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, "获取成功", c)
	}
}
